package org.jarraiders.musiclibrary.shared.domain;

import java.io.Serializable;
import java.util.UUID;

import org.jarraiders.musiclibrary.domain.Album;

/**
 * @author AlteroStudio
 */
public class AlbumDTO implements Serializable {

	private static final long serialVersionUID = 4444113592676247796L;

	private String albumId;
	private String albumName;
	private int albumYear;
	private String referencedArtistId;

	public AlbumDTO() {
	}

	/**
	 * Use this to create new AlbumDTO instance which will be transmitted to the
	 * server and converted to normal DAO
	 * 
	 * @param albumName
	 * @param albumYear
	 * @param referencedArtist
	 * @param tracksList
	 */
	private AlbumDTO(String albumName, int albumYear, String referencedArtistId) {
		this.albumId = null;
		this.albumName = albumName;
		this.albumYear = albumYear;
		this.referencedArtistId = referencedArtistId;
	}

	/**
	 * Use this to convert existing Album DAO into lightweight DTO instance.
	 * 
	 * @param album
	 *//*
	public AlbumDTO(Album album) {
		this.albumId = album.getAlbumId().toString();
		this.albumName = album.getAlbumName();
		this.albumYear = album.getAlbumYear();
		this.referencedArtistId = album.getReferencedArtist().getArtistId()
				.toString();
	}*/

	/**
	 * Use this to avoid errors in DTO creation from existing album
	 * 
	 * @param albumName
	 * @param albumYear
	 * @param referencedArtistId
	 * @return
	 */
	public static AlbumDTO getNewAlbumDTO(String albumName, int albumYear,
			String referencedArtistId) {
		return new AlbumDTO(albumName, albumYear, referencedArtistId);
	}

	public String getAlbumId() {
		return albumId;
	}
	public void setAlbumId(String uuid){
		this.albumId=uuid;
	}

	public String getAlbumName() {
		return albumName;
	}

	public void setAlbumName(String albumName) {
		this.albumName = albumName;
	}

	public int getAlbumYear() {
		return albumYear;
	}

	public void setAlbumYear(int albumYear) {
		this.albumYear = albumYear;
	}

	public String getReferencedArtistId() {
		return referencedArtistId;
	}

	public void setReferencedArtistId(String referencedArtistId) {
		this.referencedArtistId = referencedArtistId;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("AlbumDTO [albumId=");
		builder.append(albumId);
		builder.append(", albumName=");
		builder.append(albumName);
		builder.append(", albumYear=");
		builder.append(albumYear);
		builder.append(", referencedArtistId=");
		builder.append(referencedArtistId);
		builder.append("]");
		return builder.toString();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((albumId == null) ? 0 : albumId.hashCode());
		result = prime * result
				+ ((albumName == null) ? 0 : albumName.hashCode());
		result = prime * result + albumYear;
		result = prime
				* result
				+ ((referencedArtistId == null) ? 0 : referencedArtistId
						.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AlbumDTO other = (AlbumDTO) obj;
		if (albumId == null) {
			if (other.albumId != null)
				return false;
		} else if (!albumId.equals(other.albumId))
			return false;
		if (albumName == null) {
			if (other.albumName != null)
				return false;
		} else if (!albumName.equals(other.albumName))
			return false;
		if (albumYear != other.albumYear)
			return false;
		if (referencedArtistId == null) {
			if (other.referencedArtistId != null)
				return false;
		} else if (!referencedArtistId.equals(other.referencedArtistId))
			return false;
		return true;
	}
}
